from . import Blueprint, request, jsonify
from ..model.trasc_mng_model import *

trasc_mng = Blueprint('trasc_mng', __name__)


@trasc_mng.route('/addTrasc', methods=['POST'])
def add_trasc_req():
    # 新增交易流水
    name = request.get_json()['name']
    trasc_type = request.get_json()['trascType']
    money = request.get_json()['money']
    event = request.get_json()['event']
    return jsonify(chg_trasc_do(name, trasc_type, money, event))


@trasc_mng.route('/getTrascList', methods=['POST'])
def get_trasc_list_req():
    # 获取交易列表
    name = request.get_json()['name']
    trasc_type = request.get_json()['trascType']
    start_time = request.get_json()['startTm']
    end_time = request.get_json()['endTm']
    page_num = request.get_json()['pageNum']
    return jsonify(get_trasc_list_do(name, trasc_type, start_time, end_time, page_num))


@trasc_mng.route('/getTrascDtl', methods=['POST'])
def get_trasc_dtl_req():
    # 获取交易详情
    trasc_num = request.get_json()['trascFlowNum']
    name = request.get_json()['name']
    return jsonify(get_trasc_dtl_do(trasc_num, name))


@trasc_mng.route('/updateTrasc', methods=['POST'])
def update_trasc_req():
    # 修改交易流水
    trasc_flow_num = request.get_json()['trascFlowNum']
    name = request.get_json()['name']
    trasc_type = request.get_json()['trascType']
    money = request.get_json()['money']
    event = request.get_json()['event']
    return jsonify(chg_trasc_do(
        name, trasc_type, money, event, trasc_num=trasc_flow_num, typ='upd'
    ))


@trasc_mng.route('/deleteTrasc', methods=['POST'])
def delete_trasc_req():
    # 删除交易流水
    trasc_num = request.get_json()['trascFlowNum']
    return jsonify(delete_trasc_do(trasc_num))
